# -*- coding: utf-8 -*-

###########################################################################
#
#   Copyright (c) 2020  Bresee, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###########################################################################

"""
vlog web back-up service
"""

from flask import Flask
from flask_caching import Cache
import logging
import utils.common.func as func
import utils.pgsql.base.pgconn as pgconn
import utils.common.log as log 
import utils.config.websvrini as ini
import utils.common.initres as initres


from webapi.account.admin import admin_module
from webapi.account.operator import operator_module
from webapi.account.fileUpload import upload_module
from webapi.scenic.case import case_module
from webapi.scenic.device import device_module
from webapi.mission.template import template_module
from webapi.mission.activity import activity_module
from webapi.mission.element import element_module
from webapi.operation.record import record_module
from webapi.mock.base import caseconf_module
from webapi.mock.point import point_module
from webapi.seller.sellerment import seller_module
from webapi.charge.channel import channel_module
from webapi.dataBoard.capital import capital_module
from webapi.dataBoard.operat import operat_module
from webapi.dataBoard.settle import settle_module
from webapi.cost.annualfee import annualfee_module
from webapi.platform.cvm import cvm_module

from webapi.ForOtherParty.forApplet import applet_module
from webapi.ForOtherParty.forVideoProcess import videoProcess_module

SVR_HTTP_PORT = 33200
SVR_NAME = "webService"
SVR_VERSION = "0.0.1"

config={
              'CACHE_TYPE': 'redis',          # Use Redis
              'CACHE_REDIS_HOST': '10.206.0.115',  # Host, default 'localhost'
              'CACHE_REDIS_PORT': 6379,       # Port, default 6379
              'CACHE_REDIS_PASSWORD': 'SKadmin123_456',  # Password
              'CACHE_REDIS_DB': 10
}
cache = Cache(config=config)

app = Flask(__name__)
cache.init_app(app)
app.register_blueprint(admin_module)
app.register_blueprint(case_module)
app.register_blueprint(device_module)
app.register_blueprint(operator_module)
app.register_blueprint(upload_module)
app.register_blueprint(element_module)
app.register_blueprint(template_module)
app.register_blueprint(activity_module)
app.register_blueprint(record_module)
app.register_blueprint(videoProcess_module)
app.register_blueprint(applet_module)
app.register_blueprint(caseconf_module)
app.register_blueprint(point_module)
app.register_blueprint(seller_module)
app.register_blueprint(channel_module)
app.register_blueprint(capital_module)
app.register_blueprint(operat_module)
app.register_blueprint(settle_module)
app.register_blueprint(annualfee_module)
app.register_blueprint(cvm_module)

app.config["SECRET_KEY"] = "vlog_secret_key"

app.config["APPLET_KEY"] = "ZTAI5t7StH4JsKGysZfb2XgT"



@app.route("/", methods=["HEAD"])
def head():
    return "200"


if __name__ == "__main__":
 
    # flasklog = logging.getLogger('werkzeug')
    # flasklog.setLevel(logging.WARNING)
    iniPath = ""
    iniPath=initres.iniPath()

    pgDic = ini.get_postgres(iniPath)
    if pgconn.pgInit(pgDic):
        # 暂时需要连接博观vlog_data数据库
        pgconn.boguanConnect(pgDic)
        app.run(host="0.0.0.0", port=SVR_HTTP_PORT)  
    else:
        log.logging.error("pg init failed !!!!!!!!!!!!!!!!!!")
